package com.saer.client.tab;

import com.saer.client.button.BaseSearchButton;
import com.saer.client.button.ClearButton;
import com.saer.client.form.BaseSearchForm;
import com.smartgwt.client.widgets.layout.HStack;
import com.smartgwt.client.widgets.layout.VStack;
import com.smartgwt.client.widgets.tab.Tab;

public abstract class BaseSearchTab extends Tab {

	protected VStack paneStack = new VStack();
	protected BaseTab sourceTab = null;

	protected BaseSearchForm searchForm = null;
	protected BaseSearchForm searchOptionsForm = null;

	protected BaseSearchButton buttonSearch = null;
	protected ClearButton buttonClear = null;

	public BaseSearchTab(BaseTab sourceTab) {
		super("Search");

		this.sourceTab = sourceTab;
		this.setIcon("icons/16/search.png");

		this.paneStack.setSize("100%", "100%");
		this.paneStack.setMembersMargin(10);
		this.paneStack.setCanDropComponents(false);

		this.initialize();

		if (this.searchForm != null && this.buttonSearch != null) {
			this.buttonClear = new ClearButton(this.searchForm);

			HStack buttonStack = new HStack(10);
			buttonStack.addMember(this.buttonSearch);
			buttonStack.addMember(this.buttonClear);

			this.paneStack.addMember(this.searchForm);

			if (this.searchOptionsForm != null) {
				this.paneStack.addMember(this.searchOptionsForm);
			}

			this.paneStack.addMember(buttonStack);
		}

		this.setPane(this.paneStack);
	}

	protected abstract void initialize();
}
